﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using AOT;
using System;

public class Sample_1 : MonoBehaviour {

	[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
	public delegate void CallbackHandler(string msg, string msg1);

	[DllImport("__Internal")]
	static extern void test (string msg);

	[DllImport("__Internal")]
	static extern void test2 (string msg, IntPtr callback);

	// Use this for initialization
	void Start ()
	{
		#if UNITY_IPHONE

//		Debug.Log("-------");
//		test ("Hello World!");

		CallbackHandler handler = new CallbackHandler(callback2);
		IntPtr funPtr = Marshal.GetFunctionPointerForDelegate(handler);
		test2("Hello World!", funPtr);

		#endif
	}
	
	void callback(string msg)
	{
		Debug.LogFormat ("callback = {0}", msg);
	}

	[MonoPInvokeCallback(typeof(CallbackHandler))]
	static void callback2(string msg, string msg1)
	{
		Debug.LogFormat ("callback = {0} {1}", msg, msg1);
	}
}
